class WeekliesController < ApplicationController
  before_filter :login_required
  layout "need_login"
  
  def edit
    @weekly = Weekly.find params[:id]
  end

  def index
    @weeklies = Weekly.all :limit => 5, :order => '"index" desc'
  end

  def update
    weekly = Weekly.find params[:id]
    weekly.update_attributes params[:weekly]
    redirect_to :action => :index
  end

  #周刊用的一些综合统计数据
  def stat
    @stats = YAML.load(open("#{RAILS_ROOT}/config/_stat.yml"))
  end

  #中途集计榜单
  def temp_data
    @stats = YAML.load(open("#{RAILS_ROOT}/config/_list.yml"))
  end

  #查看上期确认疑似遗漏列表
  def lost_last
    @stats = YAML.load(open("#{RAILS_ROOT}/config/_lost_last.yml")).sort_by{|r| r.work.wid}
  end

  #查看本期疑似遗漏列表 (不含上期）
  def lost
      wids = YAML.load(open "#{RAILS_ROOT}/config/_lost.yml")
      wids -= YAML.load(open("#{RAILS_ROOT}/config/_lost_last.yml")).sort_by{|r| r.work.wid}.collect{|r| r.work.wid}
      @works = Work.find_all_by_wid(wids.sort, :conditions => "status = 1")
  end
  #批量检查遗漏真相
  def check_lost
      i = 0
      Work.find_all_by_wid(YAML.load(open("#{RAILS_ROOT}/config/_lost.yml")).sort, :conditions => "status = 1").each do |w|
         i+=1 unless w.get_info false, false
      end
      render :text => i
  end
  #part_count未获得投稿
  def check_part
    @works = Work.find_all_by_status 1, :conditions => "part_count is null"
  end
  def part1
    Work.find(params[:id]).update_attribute :part_count, 1
    redirect_to :action => :check_part
  end
  def status2
    Work.find(params[:id]).update_attribute :status, 2
    redirect_to :action => :check_part
  end
end
